#include <REGX52.H>
#include "LCD1602.h"
#include "Delay.h"
#include "MatrixKey.h"

int Pow(int a,int b)
{
	int num = 1;
	for(b;b>0;b--)
	{
		num = a*num;
	}
	return num;
}

void main()
{
	unsigned char num;//按键返回值
	int i = 1;//密码位数
	int Pwd = 0;//密码值存储位置
	LCD_Init();
	LCD_ShowString(1,1,"InputPassword:");
	LCD_ShowString(2,1,"****");
	while(1)
	{
		num = MatrixKey();
		if(num)
		{
			//密码模块
			if(num>0&&num<=10)//输入值为0~9
			{
				if(i<5)
				{
					Pwd += (num%10)*Pow(10,4-i); 
					LCD_ShowNum(2,i,num%10,1);
					i++;
				}
			}	
			else if(num==11)//确认
			{
				if(Pwd==1111)//密码
				{
					LCD_ShowString(2,14,"Yes");				
					}	
					else
					{
						LCD_ShowString(2,14,"No ");
					}
					Pwd = 0;
					i = 1;
					LCD_ShowString(2,1,"****");	
			}
			else if(num==12)//返回
			{
				Pwd = 0;
				i = 1;
				LCD_ShowString(2,1,"****");	
				LCD_ShowString(2,14,"   ");
			}
		}
	}	
}

